<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>顾客信息管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/css/font.css">
    <link rel="stylesheet" href="/css/xadmin.css">
    <script type="text/javascript" src="/js/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="/js/my.js"></script>
    <script type="text/javascript" src="/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>

<div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="">首页</a>
      <a href="">基础数据管理</a>
      <a>
        <cite>顾客管理</cite>
      </a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so" id="myForm" method="get" action="/customer/customerList">
            <div class="layui-input-inline">
                <select id="condition" name="condition" lay-filter="switchItem" style="text-align-last: center;">
                    <option value="请选择">请选择</option>
                    <option value="客户名称">客户名称</option>
                    <option value="法人代表">法人代表</option>
                </select>
            </div>
            <input type="text" id="conValue" name="conValue" th:value="${CV}" placeholder="请输入查询内容" autocomplete="off" class="layui-input">
            <button class="layui-btn" type="submit" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>

    <xblock>
        <button class="layui-btn layui-btn-danger" onclick=" "><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="add(this)">
            <i class="layui-icon"></i>添加
        </button>
    </xblock>

    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i>
                </div>
            </th>
            <th style="display: none">编号</th>
            <th>客户名称</th>
            <th>法人代表</th>
            <th>电话</th>
            <th>邮箱</th>
            <th>地址</th>
            <th>开始合作时间</th>
            <th>合作年限</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody>
        <tr th:each="i:${info.list}">
            <td>
                <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='2'><i
                        class="layui-icon">&#xe605;</i></div>
            </td>
            <td th:text="${i.id}" style="display: none"></td>
            <td th:text="${i.name}"></td>
            <td th:text="${i.legal_person}"></td>
            <td th:text="${i.tel}"></td>
            <td th:text="${i.email}"></td>
            <td th:text="${i.address}"></td>
            <td th:text="${i.begin_cooperation}"></td>
            <td th:text="${i.cooperation_years}"></td>
            <td class="td-manage">
                <a title="查看详情" onclick=" ">
                    <i class="layui-icon">&#xe60b;</i>
                </a>
                <a title="编辑" onclick="upDate(this)">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" onclick="del(this)">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>

    <div class="x-so">
        <a class="layui-btn layui-btn-sm" th:href="@{/customer/customerList(page=1)}">首页</a>
        <a class="layui-btn layui-btn-sm" th:href="@{/customer/customerList(page=${info.pre})}" >上一页</a>
        <a class="layui-btn layui-btn-primary ayui-btn-sm" th:text=" '当前第'+${info.cur}+'页' "></a>
        <a class="layui-btn layui-btn-sm" th:href="@{/customer/customerList(page=${info.next})}" >下一页</a>
        <a class="layui-btn layui-btn-sm" th:href="@{/customer/customerList(page=${info.totalPage})}">末页</a>
        共<span th:text="${info.total}"></span>条数据
        共<span th:text="${info.totalPage}"></span>页
    </div>
</div>
</body>
</html>

<script>
    layui.use(['layer', 'jquery', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        //根据条件进行搜索
        form.on('submit(search)', function(data){
            document.getElementById("myForm").submit();
        });
    });

    //删除用户
    function del(obj) {
        var Id = ($(obj).parent().parent().find("td").eq(1).text());
        //弹窗确认框
        layer.confirm("你确定要删除吗？",{icon:3,title:"警告"},function (index) {
            $.ajax({
                url:"/customer/delCus",
                type:"get",
                data:{"id":Id},
                dataType:"json",
                success:function (data) {
                    layer.alert(data.info);
                }
            })
        })
    }

    //打开修改页面
    function upDate(obj) {
        var Id = $(obj).parent().parent().find("td").eq(1).text();
        //打开弹窗
        x_admin_show("修改顾客信息","/customer/editCusPage?id="+Id,500,300);
    }

    //打开添加页面
    function add(obj) {
        //打开弹窗
        x_admin_show("添加顾客","/customer/addCusPage",500,300);
    }
</script>

<script>
    var _hmt = _hmt || []; (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>